﻿namespace FFF.Test.Util
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using Abp.Hangfire.Configuration;
    using Abp.Modules;
    using Abp.Reflection.Extensions;
    using Abp.Runtime.Caching.Redis;
    using Elasticsearch.Net;
    using Microsoft.Extensions.Configuration;
    using Nest;
    using FFF.Test.Util.Configuration;
    using FFF.Test.Util.Consts;
    using FFF.Test.Util.Elastic;
    using FFF.Test.Util.Localization;
    using FFF.Test.Util.Setting;
    using FFF.Test.Util.Web;
    using Ydm.Extensions;

    /// <summary>
    /// 应用层模块
    /// </summary>
    [DependsOn(
      typeof(AbpRedisCacheModule))]
    public class YdmCodeArtCoreUtilModule : AbpModule
    {
        /// <summary>
        /// 初始化应用层配置
        /// </summary>
        public override void PreInitialize()
        {
            // 初始化动态代码
            EvalHelper.InitRegister();

            // 初始化语言文件
            YdmAbpEntityLocalizationConfigurer.Configure(this.Configuration.Localization);

            base.Configuration.Settings.Providers.Add<MySettingProvider>();
            base.Configuration.Localization.WrapGivenTextIfNotFound = false;

            base.Configuration.BackgroundJobs.UseHangfire();
        }

        /// <summary>
        /// 依赖注入初始化
        /// </summary>
        public override void Initialize()
        {
            this.IocManager.RegisterAssemblyByConvention(typeof(YdmCodeArtCoreUtilModule).GetAssembly());

            //// 配置elastic
            //if (!AppConfigConsts.ElasticSearchUrl.IsNullOrEmpty())
            //{
            //    // 配置集群
            //    var nodes = AppConfigConsts.ElasticSearchUrl.Split(";").Select(x => new Uri(x)).ToArray();
            //    var pool = new StaticConnectionPool(nodes);
            //    var settings = new ConnectionSettings(pool).DefaultIndex("demo");
            //    ElasticHelper.EsClient = new ElasticClient(settings);
            //}

        }
    }
}
